package models

import (
	"strings"
	"time"

	"github.com/google/uuid"
	"gorm.io/gorm"
)

type BaseModel struct {
	ID        string     `json:"id" gorm:"primary_key"`
	CreatedAt time.Time  `json:"created_at"`
	UpdatedAt time.Time  `json:"updated_at"`
	DeletedAt *time.Time `json:"deleted_at" sql:"index"`
}

func (bm *BaseModel) BeforeCreate(tx *gorm.DB) (err error) {
	bm.ID = strings.Join(strings.Split(uuid.New().String(), "-"), "")
	return
}
